import javax.swing.table.DefaultTableModel;
import java.util.ArrayList;

/**
 * Created by LLAP on 2017/12/4.
 * Copyright (c) 2017 LLAP. All rights reserved.
 */
public class QueueTableModel extends DefaultTableModel {
    //private ArrayList<UserQueue> q;
    private ArrayList<Integer> editedIndex = new ArrayList<>();

    public QueueTableModel() {
        super();
    }

    // 序号 队列项目（ABCD） 队列名称 队列人数
    @Override
    public boolean isCellEditable(int row, int column) {
        if (column == 2) return true;
        if (column == 4) return true;
        return false;
    }

    @Override
    public void setValueAt(Object v, int row, int column) {
        super.setValueAt(v, row, column);
        int i, count = editedIndex.size();
        if (count == 0) {
            editedIndex.add(row);
        }
        else {
            for (i = 0; i < count; i++) {
                if (editedIndex.get(i).intValue() > row) {
                    editedIndex.add(i+1, row);
                    break;
                }
            }
            if (i >= count) {
                editedIndex.add(row);
            }
        }
    }

    public ArrayList<Integer> getEditedIndex() {
        return editedIndex;
    }
}
